#include <string.h>
#include "Dictionary.h"

Dictionary::Dictionary()
{
	entries = NULL;
}
Dictionary::Dictionary(char * key, void * value, char * type)
{
	entries = NULL;
	Add(key, value, type);
}
void Dictionary::Add(char * key, void * value, char * type)
{
	entries = new List<DictionaryEntry>(new DictionaryEntry(key, value, type), entries);	
}
void * Dictionary::GetValue(char * key)
{
	List<DictionaryEntry> * search = entries;
	while(search)
	{
		if(search->payload && strcmp(search->payload->GetKey(), key) == 0)
		{
			return search->payload->GetValue();
		}
		search = search->next;	
	}	
	return NULL;
}
TypedValue * Dictionary::GetTypedValue(char * key)
{
	List<DictionaryEntry> * search = entries;
	while(search)
	{
		if(search->payload && strcmp(search->payload->GetKey(), key) == 0)
		{
			return search->payload->GetTypedValue();
		}
		search = search->next;	
	}	
	printf("GetTypedValue, returning NULL\n");
	return NULL;
}
char * Dictionary::GetType(char * key)
{
	List<DictionaryEntry> * search = entries;
	while(search)
	{
		if(search->payload && strcmp(search->payload->GetKey(), key) == 0)
		{
			return search->payload->GetType();
		}
		search = search->next;	
	}	
	return NULL;
}
DictionaryEntry * Dictionary::GetEntry(char * key)
{
	List<DictionaryEntry> * search = entries;
	while(search)
	{
		if(search->payload && strcmp(search->payload->GetKey(), key) == 0)
		{
			return search->payload;
		}
		search = search->next;	
	}	
	return NULL;
}
